Skip to content

Enforce frozen backing strings#9

Merged
paracycle merged 1 commit intomainfrom
uk-enforce-frozen-backing
Mar 19, 2026
Merged

Enforce frozen backing strings#9
paracycle merged 1 commit intomainfrom
uk-enforce-frozen-backing

Conversation

@paracycle
Copy link
Copy Markdown
Member

Summary

Backing strings must now be frozen before being passed to StringView.new, Pool.new, or reset!. Previously these methods would silently freeze the string — now they raise FrozenError if it isn't already frozen.

This prevents silent mutation of the caller's string and makes the ownership contract explicit: you freeze the string, then create views into it.

String#view (via require "string_view/core_ext") continues to freeze implicitly as a convenience.

Changes

  • Replace rb_str_freeze (implicit) with sv_check_frozen_string (explicit check) at all 3 entry points
  • Merge sv_check_string + sv_check_frozen into a single sv_check_frozen_string inline helper
  • Update all tests to pass frozen strings; rename freeze-related tests to assert FrozenError
  • Update README: document frozen requirement in design decisions, fix code examples

Replace rb_str_freeze (implicit freeze) with sv_check_frozen_string
(explicit check) — backing strings must now be frozen before being
passed to StringView.new, Pool.new, or reset!. This prevents silent
mutation of strings that views point into.

- Merge sv_check_string + sv_check_frozen into sv_check_frozen_string
- Update all tests to pass frozen strings
- Update README to document the frozen requirement
@paracycle paracycle requested a review from tobi March 19, 2026 20:00
Base automatically changed from uk-string-core-ext to main March 19, 2026 20:45
@paracycle paracycle merged commit d903351 into main Mar 19, 2026
7 checks passed
@paracycle paracycle deleted the uk-enforce-frozen-backing branch March 19, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant